<?php
declare (strict_types = 1);

namespace app\admin\controller;

use app\BaseController;
use app\middleware\admin\Auth;
use app\model\Notices;
use app\model\Spoilage as SpoilageModel;
use app\model\Users;
use think\Model;

class Spoilage extends BaseController
{
    protected $middleware=[Auth::class];
    /**
     * 損耗
     * @return \think\response\Json
     * @throws \think\db\exception\DbException
     */
    public function index()
    {
        $product=\app\model\Product::select();
        $data=SpoilageModel::with(['admin','product'])->order('id','desc')->paginate(10);
        return $this->success(compact('data','product'));
    }


    public function create()
    {

        $data=request()->param();
        $data['admin_id']=request()->userid;
        SpoilageModel::create($data);
        return $this->success();
    }


    public function update($id)
    {
        $data=request()->param();
        $data['admin_id']=request()->userid;
        SpoilageModel::where('id',$id)->update($data);
        return $this->success();
    }


    public function delete($id)
    {
        SpoilageModel::where('id',$id)->delete();
        return $this->success();
    }
}
